/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.Map;
import thesis.haipv.qa.model.Question;
import thesis.haipv.qa.model.UserProfile;
import thesis.haipv.qa.persistence.QuestionDAO;

/**
 *
 * @author PHANHAI
 */
public class MyQuestion extends ActionSupport {
    
    private Paging paging;
    private ArrayList<Question> questions;
    private String page;
    
    @Override
    public String execute() throws Exception {
        Map session = ActionContext.getContext().getSession();
        UserProfile user = (UserProfile) session.get("user");
        QuestionDAO dao = new QuestionDAO();
        int _page = (page != null) ? (Integer.parseInt(page)) : 1;
        paging = new Paging(_page);
        questions = dao.getQuestionsByAsker(user.getAccountId());
        if(questions.isEmpty()) {
            paging.setIsNext(false);
        }
        return SUCCESS;
    }

    public ArrayList<Question> getQuestions() {
        return questions;
    }
    
    
}
